import request from '../data/request'
import store from 'store'
import url from '../data/url'
import { quit, fetch2 } from '../data/util'

const examinationUrl = 'admin/applyRecord/findApplyHistory.json'
const base           = url.base

new Vue({
  el: '#header',
  data: {
    loginName: store.get('loginName') || '未知',
    sayHello: '',
    examination: []
  },
  mounted: function () {

    let hours = new Date().getHours(),
        text  = ''

    if (hours >= 23 && hours <= 24 || hours >= 0 && hours <= 5) {
      text = '夜深了'
    }

    if (hours >= 6 && hours <= 8) {
      text = '早上好'
    }

    if (hours >= 9 && hours <= 10) {
      text = '上午好'
    }

    if (hours >= 11 && hours <= 13) {
      text = '中午好'
    }

    if (hours >= 14 && hours <= 18) {
      text = '下午好'
    }

    if (hours >= 19 && hours <= 22) {
      text = '晚上好'
    }

    this.sayHello = text

  },
  created() {
    this.getExamination()
  },
  methods: {
    // 我的审批信息
    getExamination() {
      fetch2(examinationUrl).then(res => {
        if (res.code === 0) {
          this.examination = res.object.elements
        } else {
          this.examination = []
        }
      })
    },
    goExamination(e) {
      e.preventDefault()
      location.href = '../examination/index.html?type=iSend'
    },
    quit: function (e) {
      e.preventDefault()

      bootbox.confirm({
        title: '提示',
        message: '<div>\
                    <h4 style="margin:.75em 0">确定退出吗？</h4>\
                  </div>',
        buttons: {
          cancel: {
            label: '取消'
          },
          confirm: {
            className: 'btn-danger',
            label: '退出'
          }
        },
        callback: (result) => {
          if (!result) {
            return
          }

          quit()

        }
      })

    }
  }
})